package com.client.ryt.basic;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Administrator on 2014/7/17.
 */
public class BaseException extends Exception {
    protected String errmsg;
    protected int errtype = 0;
    protected int loginflag = 0;
    protected String errcode;
    public BaseException(int errtype, String errmsg,String errcode){
        this.errtype = errtype;
        this.errmsg = errmsg;
        this.errcode = errcode;
    }

    public BaseException(int errtype, String errmsg){
        this(errtype,errmsg,"");
    }

    public BaseException(String errmsg,String errcode){
        this(1,errmsg,errcode);
    }

    public BaseException(String errmsg){
        this(1,errmsg,"");
    }
    public String getErrmsg() {
        return errmsg;
    }

    public void setErrmsg(String errmsg) {
        this.errmsg = errmsg;
    }

    public int getErrtype() {
        return errtype;
    }

    public void setErrtype(int errtype) {
        this.errtype = errtype;
    }

    public int getLoginflag() {
        return loginflag;
    }

    public void setLoginflag(int loginflag) {
        this.loginflag = loginflag;
    }

    public JSONObject asJson(){
        try {
            return new JSONObject("{'status':1,'msg':'"+ this.errmsg +"'}");
        } catch (JSONException e) {
            return null;
        }
    }

    public static class ExceptionType{
        /**
         * 远程数据获取异常
         */
        public static final int REMOTEDATA_ERR = 1;
        /**
         * 本地JSON解析异常
         */
        public static final int JSON_ERR = 2;
        /**
         * SQLite数据库操作异常
         */
        public static final int SQLITE_ERR = 3;
        /**
         * 无网路异常
         */
        public static final int NONETWORK_ERR = 4;

        /**
         * http请求异常
         */
        public static final int HTTP_ERR = 5;
    }
}


